/**
* @ProjectName: ShopSytem
* @Title: DBHelper.java 
* @Package com.element5th.comm 
* @Description: 产生和关闭数据库连接
* @author 第五元素小组   
* @date 2012-10-26 9:51:10 
* @version V1.0   
*/ 
package com.element5th.comm;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * The Class DBHelper.
 */
public class DBHelper {
	
	/**
	 * Gets the connection.
	 * 
	 * @return the connection
	 */
	public static Connection getConnection(){
		Connection conn = ConnectionPool.getConnection();
		
		return conn;
	}

	/**
	 * Close connection.
	 */
	public static void closeConnection(Connection conn){
		ConnectionPool.returnConnection(conn);
	}
	
	public static String getPKName(Connection conn, String tableName) {
		String pkName = null;
		ResultSet rs = null;
		try {
			rs = conn.getMetaData().getPrimaryKeys(null, null, tableName.toUpperCase());
			if(rs.next()) {
				pkName = rs.getString("COLUMN_NAME");
			}
		} catch (SQLException e) {
		}
		
		return pkName;
	}
}
